package cn.ycc1.mymcp.sse.client;

import io.modelcontextprotocol.client.McpClient;
import io.modelcontextprotocol.client.transport.WebFluxSseClientTransport;
import io.modelcontextprotocol.spec.McpSchema;
import org.springframework.web.reactive.function.client.WebClient;

import java.util.Map;

/**
 * @author ycc
 * @date 2025/4/28
 */
public class SseClientTest {
    public static void main(String[] args) {
        run();
        System.out.println("Hello, SSE!");
    }

    public static void run() {
        // SSE客户端代码示例
        var transport = new WebFluxSseClientTransport(
                // 配置WebClient基础URL
                WebClient.builder().baseUrl("http://localhost:8080")
        );

        // 构建同步MCP客户端
        var client = McpClient.sync(transport).build();

        // 初始化客户端连接
        client.initialize();

        // 调用天气预报工具
        McpSchema.CallToolResult weatherResult = client.callTool(
                new McpSchema.CallToolRequest("getWeatherForecastByLocationSse",
                        Map.of("latitude", "39.9042", "longitude", "116.4074"))
        );

        // 打印结果
        System.out.println(weatherResult.content());
    }
}
